package com.jerry.mingxing.ui.message;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jerry.mingxing.R;
import com.jerry.mingxing.ui.messageanswer.MessageAnswer;
import com.jerry.mingxing.ui.messagecomment.MessageComment;
import com.jerry.mingxing.ui.messagenotify.MessageNotify;
import com.jerry.mingxing.ui.messageservice.MessageService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/8/29.
 */
public class MessageFragment extends Fragment {

    @Bind(R.id.messagefragment_tablayout)
    TabLayout messagefragmentTablayout;
    @Bind(R.id.messagefragment_viewpager)
    ViewPager messagefragmentViewpager;
    private View view;
    private  MessagerViewPagerAdapter messagerViewPagerAdapter;
    private List<Fragment> totallist=new ArrayList<>();
    private String[] titles=new String[]{"客服","回复","评论","通知",};
    private MessageService messageService;
    private MessageAnswer messageAnswer;
    private MessageComment messageComment;
    private MessageNotify messageNotify;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.messagefragment, container, false);
        ButterKnife.bind(this, view);
        initData();
        setAdapter();
        return view;
    }

    private void initData() {
        messageService=new MessageService();
        messageAnswer=new MessageAnswer();
        messageComment =new MessageComment();
        messageNotify=new MessageNotify();
        Collections.addAll(totallist,messageService,messageAnswer,messageComment,messageNotify);

    }

    private void setAdapter() {
        messagerViewPagerAdapter= new MessagerViewPagerAdapter(getActivity().getSupportFragmentManager(),totallist,titles);
        messagefragmentViewpager.setAdapter(messagerViewPagerAdapter);
        messagefragmentTablayout.setupWithViewPager(messagefragmentViewpager);
        messagefragmentTablayout.setTabTextColors(Color.BLACK,Color.RED);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
